package com.guqj.nio.netty.websocket;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.stream.ChunkedWriteHandler;

public class ChildChannelHandler extends ChannelInitializer<SocketChannel> {

	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		// HttpServerCodec将请求和应答消息编码或者解码为HTTP消息
		ch.pipeline().addLast("http-codec", new HttpServerCodec());
		// HttpObjectAggregator将HTTP消息的多个部分组合成一条完整的HTTP消息
		ch.pipeline().addLast("aggregator", new HttpObjectAggregator(65536));
		// 向客户端发送HTML5文件，主要用于支持浏览器和服务端进行WebSocket通信
		ch.pipeline().addLast("http-chunked", new ChunkedWriteHandler());
		ch.pipeline().addLast("handler", new WebSocketHandler());
	}

}
